package com.copa.l1806;

/**
 * @author copa
 * @createDate 2023-01-09 10:08
 * @function 常规法
 */
public class Test1 {

    public int reinitializePermutation(int n) {
        int count = 0;
        int[] perm = new int[n];
        int[] arr = new int[n];
        // init
        for (int i = 0; i < n; i++) {
            perm[i] = i;
            arr[i] = i;
        }
        boolean flag = false;
        while (!flag) {
            // 按照题目要求，就算是整个数组都是已经排列的好，操作数至少为1
            count++;
            for (int i = 0; i < n; i++) {
                // 题目给出的要求
                if (i % 2 == 0) {
                    arr[i] = perm[i / 2];
                    continue;
                }
                arr[i] = perm[n / 2 + (i - 1) / 2];
            }
            flag = true;
            for (int i = 0; i < n; i++) {
                if (i < n - 1 && arr[i] > arr[i + 1]) {
                    // 如果不符合条件就为false
                    flag = false;
                }
                // 题目给出的要求
                perm[i] = arr[i];
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int n = 4;
        System.out.println(new Test1().reinitializePermutation(n));
    }
}
